package bean;

import bean.Node;

public class Link {
	private Node firstNode;
	private Node current;

	public Link(){
		firstNode=null;
	}
	public Node getFirstNode() {
		return this.firstNode;
	}

	public void reset(){
		this.current=null;
	}
	public Node next(){
		if(this.current==null){
			this.current=this.firstNode;
		}
		else{
			this.current=this.current.next();
		}
		return this.current;
	}
	
	public void addNode(int n,float dis) {
		Node temp=new Node(n,dis);
		if (this.firstNode == null) {
			this.firstNode =temp;
		} else {
			temp.next(this.firstNode);
			this.firstNode=temp;
		}
	}
	
	void remove(int index){
		Node pre = null;
		Node cur = firstNode;
		
		while(cur != null)
		{
			if(cur.index() == index)
			{
				if(pre == null)
				{
					firstNode = cur.next();
				}
				else
				{
					pre.next(cur.next());
				}
				return;
			}
			pre = cur;
			cur = cur.next();
		}
		
	}
}
